package com.lgc.login

import android.content.Context
import android.content.Intent
import android.view.View
import androidx.databinding.ObservableField
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.lgc.login.net.LoginReqBody
import com.lgc.login.repo.ILoginResource
import com.lgc.login.ui.TextLiveDataActivity
import com.lgc.login.ui.TextViewModel
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.launch

/**
 * 登录页面逻辑viewmodel
 */
class LoginViewModel : ViewModel() {
    val obMobile=ObservableField<String>()
    val obPassword=ObservableField<String>()
    val catchEx= CoroutineExceptionHandler { coroutineContext, throwable ->
        LogUtils.e("异步${throwable.message}")
    }
    fun goLogin(){//登录逻辑
        viewModelScope.launch(catchEx) {
//            resource.checkRegister("18600540721")
//            resource.requestLogin(LoginReqBody("18600540721","cn12345"))
            LogUtils.i("点击了登录按钮${obMobile.get()}")
            ToastUtils.showShort("点击了登录按钮")
        }
    }

    fun wechat(context:Context){
        ToastUtils.showShort("点击了微信登录")
        context.startActivity(Intent(context,TextLiveDataActivity::class.java))
    }

    fun qq(view: View){

        ToastUtils.showShort("点击了QQ登录")
    }

    fun weibo(context:Context){
        ToastUtils.showShort("点击了微博登录")
    }
}
